package com.itheima.service.Impl;

import com.itheima.mapper.SetmealMapper;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SetmealServiceImpl implements SetmealService {
    @Autowired
    private SetmealMapper setmealMapper;

    /**
     * 获取所有套餐信息
     * @return
     */
    public List<Setmeal> getSetmeal() {
        return setmealMapper.getSetMeal();
    }

    /**
     * 根据套餐id查询套餐详情，包含（套餐基本信息、套餐关联的检查组、检查组关联的检查项）
     * @param id
     * @return
     */
    public Setmeal findById(Integer id) {
        //获取对应套餐
        Setmeal setmeal = setmealMapper.findById(id);
        //获取检查组
        List<CheckGroup> list = setmealMapper.findGroups(setmeal.getId());
        list.forEach(group->{
            List<CheckItem> list1 = setmealMapper.findItems(group.getId());
            group.setCheckItems(list1);
        });

        setmeal.setCheckGroups(list);
        return setmeal;
    }
}
